// 函數功能:遞歸遍歷文件
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <io.h>
int nFileNum;
// 函數功能:瀏覽文件
void scanfile(char* pPath, char* pName)
{
?char strFileName[256];
?nFileNum++;
?strcpy(strFileName, pPath);
?strcat(strFileName, pName);
?printf("%s/n", strFileName);
}
// 函數功能:瀏覽目錄,遞歸
void scandir(char *strCurPath)
{
?char strTemp[2048];
?struct _finddata_t ffblk;
?int nReturn = 0;
?strcpy(strTemp, strCurPath);
?strcat(strTemp, "*.*");
?long lHandle = long(_findfirst(strTemp, &ffblk));
?while (lHandle != -1 && nReturn != -1)
?{
? if(strcmp(ffblk.name, ".") == 0 || strcmp(ffblk.name, "..") == 0)
? {
? ?nReturn = _findnext(lHandle, &ffblk);
? ?continue;
? }
? if (ffblk.attrib & _A_SUBDIR)
? {
? ?// Is Dir
? ?strcpy(strTemp, strCurPath);
? ?strcat(strTemp, ffblk.name);
? ?strcat(strTemp, "http://");
? ?scandir(strTemp);
? }
? else
? {
? ?// Is File
? ?scanfile(strCurPath, ffblk.name);
? }
? nReturn = _findnext(lHandle, &ffblk);
?}
?_findclose(lHandle);
}
void main()
{
?nFileNum = 0;
?scandir("c://");
printf("/nTotal files: %d/n", nFileNum);
}